package com.yanggu.scala.chapater08.accompanyObject

object ChildJoinGame {

  def main(args: Array[String]): Unit = {
    val child1 = new Child("张三")
    val child2 = new Child("王五")
    val child3 = new Child("赵六")
    Child.join(child1)
    Child.join(child2)
    Child.join(child3)
    println(Child.number)
  }

}

class Child(var name : String)


object Child {

  //伴生对象中的字段是共享的。和java的static字段类似
  var number : Int = _

  def join(child: Child): Unit = {
    println("一个小孩加入了: " + child.name)
    number += 1
  }


}
